'use strict';

module.exports = options => {
  return async function checkLogin(ctx, next) {
    const filter = Array.isArray(options.filter) ? options.filter : [];
    if (filter.includes(ctx.request.url)) {
      await next();
      return;
    }
    if (ctx.response.isLogin()) {
      await next();
      return;
    }
    ctx.response.removeLogin();
    ctx.body = ctx.response.errResult(4003);
  };
};
